package com.haixiaoke.saas.common.weChat.domain;

import lombok.Data;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @Author panda
 * @Date 2024/4/15
 **/
@Data
@XmlRootElement(name = "xml")
@XmlAccessorType(XmlAccessType.FIELD)
public class ParseParam {

    /**
     * 订单总金额,必填
     */
    @XmlElement(name = "total_fee")
    private String totalFee;

    /**
     * 微信支付订单号,必填
     */
    @XmlElement(name = "transaction_id")
    private String transactionId;

    /**
     * 商户订单号,必填
     */
    @XmlElement(name = "out_trade_no")
    private String outTradeNo;

    /**
     * 附带数据，可回调时使用
     */
    @XmlElement(name = "attach")
    private String attach;

    /**
     * 返回状态码,SUCCESS/FAIL,必填
     * <p>
     * 此字段是通信标识，非交易标识，交易是否成功需要查看result_code来判断
     */
    @XmlElement(name = "return_code")
    private String returnCode;

    /**
     * 返回信息，如非空，为错误原因
     */
    @XmlElement(name = "return_msg")
    private String returnMsg;

    /**
     * 业务结果,	SUCCESS/FAIL,必填
     */
    @XmlElement(name = "result_code")
    private String resultCode;

    /**
     * 错误代码,错误返回的信息描述
     */
    @XmlElement(name = "err_code")
    private String errCode;

    /**
     * 错误代码描述,错误返回的信息描述
     */
    @XmlElement(name = "err_code_des")
    private String errCodeDes;

    /**
     * 微信支付分配的商户号,必填
     */
    @XmlElement(name = "mch_id")
    private String mchId;

    /**
     * 随机字符串,必填
     */
    @XmlElement(name = "nonce_str")
    private String nonceStr;

    /**
     * 支付完成时间,必填
     */
    @XmlElement(name = "time_end")
    private String timeEnd;

    /**
     * 签名,必填
     */
    @XmlElement(name = "sign")
    private String sign;

    /**
     * 小程序id,必填
     */
    @XmlElement(name = "appid")
    private String appId;

    /**
     * 微信支付分配的终端设备号
     */
    @XmlElement(name = "device_info")
    private String deviceInfo;

    /**
     * 签名类型，目前支持HMAC-SHA256和MD5，默认为MD5
     */
    @XmlElement(name = "sign_type")
    private String signType;

    /**
     * 用户在商户appid下的唯一标识,必填
     */
    @XmlElement(name = "openid")
    private String openId;

    /**
     * 是否关注公众账号,已废弃，默认统一返回N,必填
     */
    @XmlElement(name = "is_subscribe")
    private String isSubscribe;

    /**
     * 交易类型,JSAPI、NATIVE、APP,必填
     */
    @XmlElement(name = "trade_type")
    private String tradeType;

    /**
     * 付款银行,必填
     */
    @XmlElement(name = "bank_type")
    private String bankType;

    /**
     * 应结订单金额,应结订单金额=订单金额-非充值代金券金额，应结订单金额<=订单金额。
     */
    @XmlElement(name = "settlement_total_fee")
    private String settlementTotalFee;

    /**
     * 货币种类
     */
    @XmlElement(name = "fee_type")
    private String feeType;

    /**
     * 现金支付金额,必填
     */
    @XmlElement(name = "cash_fee")
    private String cashFee;

    /**
     * 现金支付货币类型
     */
    @XmlElement(name = "cash_fee_type")
    private String cashFeeType;

    /**
     * 总代金券金额
     */
    @XmlElement(name = "coupon_fee")
    private String couponFee;

    /**
     * 代金券使用数量
     */
    @XmlElement(name = "coupon_count")
    private String couponCount;

    /**
     * 代金券类型
     */
    @XmlElement(name = "coupon_type_$n")
    private String couponType;

    /**
     * 代金券ID
     */
    @XmlElement(name = "coupon_id_$n")
    private String couponId;

    /**
     * 单个代金券支付金额
     */
    @XmlElement(name = "coupon_fee_$n")
    private String couponFeeTwo;

    public String resultFail(String code, String msg) {
        return "<xml>" +
                "<return_code><![CDATA[" + code + "]]></return_code>" +
                "<return_msg><![CDATA[" + msg + "]]></return_msg>" +
                "</xml>";
    }

    public String resultFail() {
        return "<xml>" +
                "<return_code><![CDATA[" + "FAIL" + "]]></return_code>" +
                "<return_msg><![CDATA[" + "失败" + "]]></return_msg>" +
                "</xml>";
    }

    public String resultSuccess() {
        return "<xml>" +
                "<return_code><![CDATA[" + "SUCCESS" + "]]></return_code>" +
                "<return_msg><![CDATA[" + "OK" + "]]></return_msg>" +
                "</xml>";
    }

    public String resultSuccess(String code, String msg) {
        return "<xml>" +
                "<return_code><![CDATA[" + code + "]]></return_code>" +
                "<return_msg><![CDATA[" + msg + "]]></return_msg>" +
                "</xml>";
    }
}
